/*    */ package com.cr.framework.shiro.web.filter.captcha;
/*    */ 
/*    */ import com.cr.common.utils.ShiroUtils;
/*    */ import com.cr.common.utils.MyStringUtils;
/*    */ import javax.servlet.ServletRequest;
/*    */ import javax.servlet.ServletResponse;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import org.apache.shiro.web.filter.AccessControlFilter;
/*    */ 
/*    */ public class CaptchaValidateFilter extends AccessControlFilter {
/*    */   private boolean captchaEnabled = true;
/*    */   
/* 27 */   private String captchaType = "math";
/*    */   
/*    */   public void setCaptchaEnabled(boolean captchaEnabled) {
/* 31 */     this.captchaEnabled = captchaEnabled;
/*    */   }
/*    */   
/*    */   public void setCaptchaType(String captchaType) {
/* 36 */     this.captchaType = captchaType;
/*    */   }
/*    */   
/*    */   public boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
/* 42 */     request.setAttribute("captchaEnabled", Boolean.valueOf(this.captchaEnabled));
/* 43 */     request.setAttribute("captchaType", this.captchaType);
/* 44 */     return super.onPreHandle(request, response, mappedValue);
/*    */   }
/*    */   
/*    */   protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
/* 51 */     HttpServletRequest httpServletRequest = (HttpServletRequest)request;
/* 53 */     if (!this.captchaEnabled || !"post".equals(httpServletRequest.getMethod().toLowerCase()))
/* 55 */       return true; 
/* 57 */     return validateResponse(httpServletRequest, httpServletRequest.getParameter("validateCode"));
/*    */   }
/*    */   
/*    */   public boolean validateResponse(HttpServletRequest request, String validateCode) {
/* 62 */     Object obj = ShiroUtils.getSession().getAttribute("KAPTCHA_SESSION_KEY");
/* 63 */     String code = String.valueOf((obj != null) ? obj : "");
/* 65 */     request.getSession().removeAttribute("KAPTCHA_SESSION_KEY");
/* 66 */     if (MyStringUtils.isEmpty(validateCode) || !validateCode.equalsIgnoreCase(code))
/* 68 */       return false; 
/* 70 */     return true;
/*    */   }
/*    */   
/*    */   protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
/* 76 */     request.setAttribute("captcha", "captchaError");
/* 77 */     return true;
/*    */   }
/*    */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-framework-4.7.0.jar!\com\cr\framework\shiro\web\filter\captcha\CaptchaValidateFilter.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */